﻿Imports TransportadoraToledoDAL

Public Class FuncionariosBLL

#Region "Propriedades"


    Private codigo As Integer
    Public Property pCodigo() As String
        Get
            Return codigo
        End Get
        Set(ByVal value As String)
            codigo = value
        End Set
    End Property


    Private cargo As Integer
    Public Property pcargo() As Integer
        Get
            Return cargo
        End Get
        Set(ByVal value As Integer)
            cargo = value
        End Set
    End Property

    Private cargoDesc As String
    Public Property pcargoDesc() As String
        Get
            Return cargoDesc
        End Get
        Set(ByVal value As String)
            cargoDesc = value
        End Set
    End Property

    Private data_admissao As Date
    Public Property pda_admissao() As Date
        Get
            Return data_admissao
        End Get
        Set(ByVal value As Date)
            data_admissao = value
        End Set
    End Property


    Private salario As Double
    Public Property psalario() As Double
        Get
            Return salario
        End Get
        Set(ByVal value As Double)
            salario = value
        End Set
    End Property


    Private ch_semanal As Integer
    Public Property pch_semanal() As Integer
        Get
            Return ch_semanal
        End Get
        Set(ByVal value As Integer)
            ch_semanal = value
        End Set
    End Property


    Private ativo As Char
    Public Property pativo() As Char
        Get
            Return ativo
        End Get
        Set(ByVal value As Char)
            ativo = value
        End Set
    End Property


    Private nome As String
    Public Property pnome() As String
        Get
            Return nome
        End Get
        Set(ByVal value As String)
            nome = value
        End Set
    End Property


    Private logradouro As String
    Public Property plogradouro() As String
        Get
            Return logradouro
        End Get
        Set(ByVal value As String)
            logradouro = value
        End Set
    End Property


    Private complemento As String
    Public Property pcomplemento() As String
        Get
            Return complemento
        End Get
        Set(ByVal value As String)
            complemento = value
        End Set
    End Property


    Private numero As String
    Public Property pnumero() As String
        Get
            Return numero
        End Get
        Set(ByVal value As String)
            numero = value
        End Set
    End Property


    Private bairro As String
    Public Property pbairro() As String
        Get
            Return bairro
        End Get
        Set(ByVal value As String)
            bairro = value
        End Set
    End Property


    Private cidade As String
    Public Property pCidade() As String
        Get
            Return cidade
        End Get
        Set(ByVal value As String)
            cidade = value
        End Set
    End Property


    Private cep As String
    Public Property pcep() As String
        Get
            Return cep
        End Get
        Set(ByVal value As String)
            cep = value
        End Set
    End Property


    Private tipo As Char
    Public Property ptipo() As Char
        Get
            Return tipo
        End Get
        Set(ByVal value As Char)
            tipo = value
        End Set
    End Property


    Private cnh As String
    Public Property pcnh() As String
        Get
            Return cnh
        End Get
        Set(ByVal value As String)
            cnh = value
        End Set
    End Property


    Private fun_codigo As Integer
    Public Property pfun_codigo() As Integer
        Get
            Return fun_codigo
        End Get
        Set(ByVal value As Integer)
            fun_codigo = value
        End Set
    End Property


    Private telefone_fixo As String
    Public Property ptelefone_fixo() As String
        Get
            Return telefone_fixo
        End Get
        Set(ByVal value As String)
            telefone_fixo = value
        End Set
    End Property


    Private celular As String
    Public Property pcelular() As String
        Get
            Return celular
        End Get
        Set(ByVal value As String)
            celular = value
        End Set
    End Property


    Private telefone_recado As String
    Public Property ptelefone_recado() As String
        Get
            Return telefone_recado
        End Get
        Set(ByVal value As String)
            telefone_recado = value
        End Set
    End Property


    Private cod_cidade As Integer
    Public Property pcod_cidade() As Integer
        Get
            Return cod_cidade
        End Get
        Set(ByVal value As Integer)
            cod_cidade = value
        End Set
    End Property


#End Region

    Sub New()

    End Sub

    Sub New(ByVal nome As String, ByVal logradouro As String, ByVal complemento As String, ByVal numero As String, ByVal bairro As String,
            ByVal cod_cidade As Integer, ByVal cep As String, ByVal cargo As Integer, ByVal data_admissao As Date, ByVal salario As Double, ByVal ch_semanal As Integer,
            ByVal telefone_fixo As String, ByVal celular As String, ByVal telefone_recado As String)
        Me.cargo = cargo
        Me.data_admissao = data_admissao
        Me.salario = salario
        Me.ch_semanal = ch_semanal
        Me.nome = nome
        Me.logradouro = logradouro
        Me.complemento = complemento
        Me.numero = numero
        Me.bairro = bairro
        Me.cod_cidade = cod_cidade
        Me.cep = cep
        Me.cnh = cnh
        Me.telefone_fixo = telefone_fixo
        Me.celular = celular
        Me.telefone_recado = telefone_recado
    End Sub

    Sub limpar()
        Me.cargo = Nothing
        Me.data_admissao = Nothing
        Me.salario = Nothing
        Me.ch_semanal = Nothing
        Me.ativo = Nothing
        Me.nome = Nothing
        Me.logradouro = Nothing
        Me.complemento = Nothing
        Me.numero = Nothing
        Me.bairro = Nothing
        Me.cidade = Nothing
        Me.cep = Nothing
        Me.tipo = Nothing
        Me.cnh = Nothing
        Me.fun_codigo = Nothing
        Me.codigo = Nothing
        Me.telefone_fixo = Nothing
        Me.celular = Nothing
        Me.telefone_recado = Nothing
        Me.cod_cidade = Nothing
    End Sub

    Sub inserir()
        Dim objDAL As New FuncionariosDAL
        Try
            If (nome = "" Or logradouro = "" Or numero = "" Or bairro = "" Or cep = "" Or tipo = "" Or cargo = 0 Or salario = 0 Or ch_semanal = 0) Then
                Throw New Exception("Ainda há campos a serem preenchidos.")
            Else
                Me.codigo = objDAL.inserir(nome, logradouro, complemento, numero, bairro, cod_cidade, cep, tipo, cargo, data_admissao, salario, ch_semanal, cnh, telefone_fixo, celular, telefone_recado)
            End If

        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub

    Sub alterar()
        Dim objDAL As New FuncionariosDAL
        Try
            If (nome = "" Or logradouro = "" Or numero = "" Or bairro = "" Or cep = "" Or tipo = "" Or cargo = 0 Or salario = 0 Or ch_semanal = 0) Then
                Throw New Exception("Ainda há campos a serem preenchidos.")
            Else
                objDAL.alterar(fun_codigo, nome, logradouro, complemento, numero, bairro, cod_cidade, cep, tipo, cargo, data_admissao, salario, ch_semanal, cnh, telefone_fixo, celular, telefone_recado)
            End If
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub

    Sub excluir()
        Dim objDAL As New FuncionariosDAL
        Try
            objDAL.excluir(fun_codigo)
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
    End Sub

    Function localizar(ByVal descricao As String, ByVal opcao As String) As DataTable
        Dim tab As DataTable
        Dim objDAL = New FuncionariosDAL
        Try

            tab = objDAL.localizar(descricao, opcao)
        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
        Return tab
    End Function

    Sub localizar(ByVal fun_codigo As Integer)
        Dim tab As DataTable
        Dim objDAL As New FuncionariosDAL
        Try
            tab = objDAL.localizar(fun_codigo)
            If (tab.Rows.Count > 0) Then
                Me.codigo = tab.Rows(0)("pes_codigo").ToString
                Me.fun_codigo = tab.Rows(0)("fun_codigo").ToString
                Me.nome = tab.Rows(0)("pes_nome").ToString
                Me.logradouro = tab.Rows(0)("pes_logradouro").ToString
                Me.complemento = tab.Rows(0)("pes_complemento").ToString
                Me.numero = tab.Rows(0)("pes_numero").ToString
                Me.bairro = tab.Rows(0)("pes_bairro").ToString
                Me.cidade = tab.Rows(0)("nom_cidade").ToString
                Me.cod_cidade = tab.Rows(0)("cod_cidade").ToString
                Me.cep = tab.Rows(0)("pes_cep").ToString
                Me.cargo = tab.Rows(0)("cf_codigo").ToString
                Me.cargoDesc = tab.Rows(0)("cf_descricao").ToString
                Me.data_admissao = tab.Rows(0)("fun_data_admissao").ToString
                Me.salario = tab.Rows(0)("fun_salario").ToString
                Me.ch_semanal = tab.Rows(0)("fun_ch_semanal").ToString
                Me.ativo = tab.Rows(0)("fun_ativo_sn").ToString
                Me.telefone_fixo = tab.Rows(0)("pes_telefone_fixo").ToString
                Me.celular = tab.Rows(0)("pes_celular").ToString
                Me.telefone_recado = tab.Rows(0)("pes_telefone_recado").ToString
                If cargo = 1 Then
                    tab = objDAL.localizarCNH(fun_codigo)
                    If (tab.Rows.Count > 0) Then
                        Me.cnh = tab.Rows(0)("mot_cnh").ToString
                    Else
                        Me.cnh = ""
                    End If
                Else
                    Me.cnh = ""
                End If
            Else
                limpar()
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Function localizarPrimeiroUltimo(ByVal opcao As String) As Integer
        Dim tab As DataTable = Nothing
        Dim codigo As Integer = 0
        Dim objDAL As FuncionariosDAL
        Try
            If (opcao = "ultimo") Then
                objDAL = New FuncionariosDAL
                tab = objDAL.localizarPrimeiroUltimo(opcao)
                If (tab.Rows(0)("fun_codigo").ToString <> "") Then
                    codigo = tab.Rows(0)("fun_codigo").ToString
                End If
            ElseIf (opcao = "primeiro") Then
                objDAL = New FuncionariosDAL
                tab = objDAL.localizarPrimeiroUltimo(opcao)
                If (tab.Rows(0)("fun_codigo").ToString <> "") Then
                    codigo = tab.Rows(0)("fun_codigo").ToString
                End If
            End If


        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
        Return codigo
    End Function

    Function localizarProxAnterior(ByVal opcao As String, ByVal codigo As Integer) As Integer
        Dim tab As DataTable = Nothing
        Dim CodigoP As Integer = 0
        Dim objDAL As FuncionariosDAL
        Try

            objDAL = New FuncionariosDAL
            tab = objDAL.localizarProxAnterior(opcao, codigo)
            If (tab.Rows.Count > 0) Then
                CodigoP = tab.Rows(0)("fun_codigo").ToString
            End If

        Catch ex As Exception
            Throw ex
        End Try
        objDAL = Nothing
        Return CodigoP
    End Function

End Class
